package user;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import role.Role;
import role.RoleDao;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private User user=new User();
	private UserDao userDao;
	private Role role=new Role();
	private RoleDao roleDao; 
	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public UserDao getUserDao() {
		return userDao;
	}
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	public Role getRole() {
		return role;
	}
	public void setRole(Role role) {
		this.role = role;
	}
	public RoleDao getRoleDao() {
		return roleDao;
	}
	public void setRoleDao(RoleDao roleDao) {
		this.roleDao = roleDao;
	}
	public static long getSerialVersionUID() {
		return serialVersionUID;
	}
	public String logon(){
		this.user=this.userDao.userLogon(user);
		if(this.user!=null){
			HttpSession session = ServletActionContext.getRequest().getSession();
			session.setAttribute("user",this.user);
			System.out.println("登陆成功"+this.user.getUser_email());
			return SUCCESS;
		}else{
			this.addFieldError("user.user_account", "用户名或密码错误");
			return "input";
		}
	}
	public String input(){
		return "input";
	}
	public String execute(){
		
		return SUCCESS;
	}
}
